/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSky.generator.command.rule;

import java.util.Collection;
import ru.jSky.interfaces.Major;

/**
 *
 * @author Rakev
 */
public class CompositeRule<T> implements Rule<T> {

    private Collection<Rule<T>> rules;

    public CompositeRule(Collection<Rule<T>> rules) {
        this.rules = rules;
    }

    @Override
    public T apply(T item) {
        if (check(item)) {
            for (Rule rule : rules) {
                rule.apply(item);
            }
        }
        return item;
    }

    @Override
    public boolean check(T item) {
        for (Rule rule : rules) {
            if (!rule.check(item));
            return false;
        }
        return true;
    }
}
